package io.jee.runshan.service.impl;

import io.jee.medusa.orm.condition.Condition;
import io.jee.medusa.orm.condition.ConditionGroup;
import io.jee.runshan.dao.IPreSaleOrderDao;
import io.jee.runshan.service.ITimerService;

import java.util.Date;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
@Transactional
public class TimerServiceImpl implements ITimerService {
	private static final Logger logger = LoggerFactory.getLogger(TimerServiceImpl.class);
	@Resource
	private IPreSaleOrderDao preSaleOrderDao;

	@Scheduled(cron="0 * * * * ?")
	@Override
	public void autoCancelOrder() {
		logger.debug("autoCancelOrder scan start......");
		ConditionGroup group = new ConditionGroup();
		group.and(Condition.onDate("cancelTimer").let(new Date()));
		group.and(Condition.onNumber("status").eq(0));
		preSaleOrderDao.update("status", 97, group);
		logger.debug("autoCancelOrder scan done......");
	}
	
}
